package com.ccyl.util;

import java.sql.*;

public class JDBCTools {
    //Shit! I forgot my MySQL password, again!!!!
    private static Connection connection;
    private static String url="jdbc:mysql://数据库ip地址/qndxx?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC";
    private static String user="用户名";
    private static String password="密码";
    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    //获取连接
    public static Connection getConnection() {
        try {
            connection=DriverManager.getConnection(url,user,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connection;
    }
    //释放连接
    public static void release(Connection connection, Statement statement, ResultSet resultSet) {
        try {
          if (connection!=null) {
              connection.close();
          }
          if (statement!=null) {
              statement.close();
          }
          if (resultSet!=null) {
              resultSet.close();
          }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
